<template>
  <div ref="todayRecordPic" style="width: 450px; height: 60vh" />
</template>

<script setup lang="ts">
import { ref, computed, watch, type Ref, onMounted } from "vue";
import { useAppStoreHook } from "@/store/modules/app";
import { delay, useDark, useECharts, type EchartOptions } from "@pureadmin/utils";
import { yinYangPicApi } from "@/api/count";
const { isDark } = useDark();
const theme: EchartOptions["theme"] = computed(() => {
  return isDark.value ? "dark" : "light";
});

const todayRecordPic = ref<HTMLDivElement | null>(null);
const { setOptions, resize } = useECharts(todayRecordPic as Ref<HTMLDivElement>, {
  theme
});

// 获取接口数据
onMounted(() => {
  getData();
});

let dataList = [];

async function getData() {
  const result = await yinYangPicApi();
  console.log("饼图接口数据", result);
  if (result.code == 200) {
    dataList = result.data;
    console.log(dataList);
    setOptionsData();
  }
}

// [
//   { value: 1048, name: "阴性" },
//   { value: 735, name: "阳性" },
//   { value: 580, name: "待检测" },
//   { value: 484, name: "未打卡" }
// ];
function setOptionsData() {
  setOptions({
    title: {
      text: "今日情况"
    },
    tooltip: {
      trigger: "item"
    },
    legend: {
      top: "5%",
      left: "60%"
    },

    series: [
      {
        name: "今日情况",
        type: "pie",
        radius: ["40%", "70%"],
        center: ["45%", "62%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: "#fff",
          borderWidth: 2
        },
        label: {
          show: false,
          position: "center"
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: "bold"
          }
        },
        labelLine: {
          show: false
        },
        color: ["#18bc37", "#e43d33", "#f3a73f", "#8f939c", "#73c0de", "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc"],
        data: dataList
      }
    ]
  });
}

watch(
  () => useAppStoreHook().getSidebarStatus,
  () => {
    delay(600).then(() => resize());
  }
);
</script>
